﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Query.DishOrderModule.ViewObject;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Repositories;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.DishOrderModule.QueryObject
{
    public class DishOrderQO : IApplicationQueryObject
    {
        private IQueryable<DishOrderVO> GetDishOrderVOSet()
        {
            IEntityRepository<DishOrder> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<DishOrder>();

            IQueryable<DishOrderVO> list = from o in repository.Objects
                                           select new DishOrderVO()
                                           {
                                               ID = o.ID,
                                               OrderDate = o.OrderDate,
                                               OrderTypeCode = o.OrderType,
                                               SiteId = o.SiteID,
                                               TotalCost = o.TotalCost,
                                               TotalPrice = o.TotalPrice,
                                               OrderStateCode = o.OrderState,
                                           };

            return list;
        }

        public DishOrderVO[] QueryDishOrderVOByPager(ISpecification<DishOrderVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<DishOrderVO> list = GetDishOrderVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<DishOrderVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}
